export type CanWrite<T> = {
  -readonly [K in keyof T]: T[K]
}

/**
 * @description 构造一个由所需的 T 的键组成的类型。
 * @example
 * interface User {
 *   name: string;
 *   num: number;
 *   age?: number;
 * }
 * type RequiredUserKeys = RequiredKeys<User>;
 * 结果为：`'name' | 'num'`
 */
export type RequiredKeys<T> = {
  [K in keyof T]-?: Record<string, never> extends Pick<T, K> ? never : K
}[keyof T];



/**
 * @description 构造由 T 中所有值的并集组成的类型。
 * @example
 * type User = {
 *   id: number;
 *   name: string;
 * };
 * type UserValues = ValueOf<User>;
 * 结果为： `number | string`
 */
export type ValueOf<T> = T[keyof T];


/**
 * @description 提取组件`Event`类型
 */
export type ComponentEmit<T> =
    T extends new () => { $emit: infer E; } ? NonNullable<E> :
    T extends (props: any, ctx: { emit: infer E; }, ...args: any) => any ? NonNullable<E> :
    Record<string,any>;



/**
 * @description 提取组件`Props`类型
 */

export type ComponentProps<T> =
    T extends new () => { $props: infer P; } ? NonNullable<P> :
    T extends (props: infer P, ...args: any) => any ? P :
    Record<string,any>;

/**
 * @description 提取组件`Slot`类型
 */
export type ComponentSlots<T> =
    T extends new () => { $slots: infer S; } ? NonNullable<S> :
    T extends (props: any, ctx: { slots: infer S; }, ...args: any) => any ? NonNullable<S> :
    Record<string,any>;